function generateTable(data,container){
   // console.log(data)
    data[0].sort(function(item1,item2){
        return Number(item1.id) - Number(item2.id)
    })
    data[1].sort(function(item1,item2){
        return Number(item1.id) - Number(item2.id)
    })
    
    var arr2 = data[1]
    arr2.sort(function(item1,item2){
        return item1.id + '' > item2.id+''
    })

    var idMinLength = data[0]>0 ? (data[0][0].id+'').length : 0
    var idMaxLength = data[0].length > 0 ? (data[0][data[0].length-1].id+'').length : 0
    var rowSpanMax = idMaxLength - idMinLength + 1;
    function getItemRowSpan(index,arr){
        var span = 1;
        var id = arr[index].id
        var idLength = (id + '').length
        var hasChild = false
        if(idLength < idMaxLength){
            for(var i=0;i<arr.length;i++){
                if(arr[i].pId == id){
                    hasChild = true
                }
            }
        }
        if(hasChild){
            return span
        } else {
            return idMaxLength - idLength+1 
        }
    }
    function getItemColSpan(index,arr){
        var span = 1
        var id = arr[index].id
        for(var i=0;i<arr.length;i++){
            if(arr[i].pId == id){
                span = span + getItemColSpan(i,arr)
            }
        }
        return span > 1 ? span-1 : span
    }
    var tableColSpan = 1
    function getHtmlText(){
        var arr = data[0]
        var html = '<thead><tr><td rowspan="'+rowSpanMax+'" colspan="1">项目</td><td rowspan="'+rowSpanMax+'" colspan="1">代码</td>'
        for(var i=0;i<arr.length;i++){
            if(i>0 && (arr[i].id+'').length > (arr[i-1].id+'').length){
                html += '</tr><tr>'
            }
            var colSpan = getItemColSpan(i,arr)
            var rowSpan = getItemRowSpan(i,arr)
            if((arr[i].id + '').length == idMinLength){
                tableColSpan += colSpan
            }
            html += '<td colspan="'+ colSpan +'" rowspan="'+rowSpan+'">'+arr[i].name+'</td>'
        }
        html += '</tr></thead><tbody><tr><td>总计</td></tr>'
        for(var j=0;j<arr2.length;j++){
            html += '<tr><td>'+arr2[j].name+'</td></tr>'
        }
        
        html = '<table cellpadding="0" cellspacing="0" class="JS_table tj-right-table main-table">'+html+'</tbody></table>'
        container.innerHTML = html
    }
    getHtmlText()
}